package com.yumei.trader.gym.act;

import android.app.Activity;
import android.content.Context;

import com.yumei.trader.gym.client.TGApplication;
import com.yumei.trader.gym.dbase.sqlite.SqliteActObject;
import com.yumei.trader.gym.object.ActObj;


public class SLTraderAct extends TraderAct {

    private ActObj accountEl;

    public SLTraderAct(Context context){
        super(context);
    }

    @Override
    protected double loadCashAccount() {

        Activity act  = (Activity)context;
        TGApplication mApp = (TGApplication)act.getApplication();

        /*
        Activity act  = (Activity)context;
        LazyApplication mApp = (LazyApplication)act.getApplication();
        String cashStr = mApp.getDBMrg().getValue(DBaseConst.Trade_Cash,"10000");
        return Double.parseDouble(cashStr);*/

        accountEl = SqliteActObject.getInstance(context).getAccount(mApp.getUserId());
        return accountEl.account;
    }



    @Override
    protected void saveCashAccount() {

        /*
        Activity act  = (Activity)context;
        LazyApplication mApp = (LazyApplication)act.getApplication();
        mApp.getDBMrg().addParam(DBaseConst.Trade_Cash,String.valueOf(getCashValue()));
        mApp.getDBMrg().save();*/
        //SqliteAccountObject.getInstance(context).setAccount(accountEl.userId, getValue());
        float profit = 0.0f;
        for (BSAction action : getBsArr()){
            if (action.actionType.equals("Long")){
                profit = profit + (action.sellPrice - action.buyPrice) * action.count;
            }else if (action.actionType.equals("Short")){
                profit = profit + (-(action.sellPrice - action.buyPrice)) * action.count;
            }
        }
        System.out.println("@@@@@@@@@" + (profit + getProfit()) + "@@@@@@@@" + getBsArr().size());
        SqliteActObject.getInstance(context).setProfit(accountEl.userId, (int)(profit + getProfit()));
    }
}
